package cn.com.tuns.assess.qsb.frame.util;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import androidx.core.content.FileProvider;
import cn.com.tuns.assess.qsb.BuildConfig;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class AndroidShareUtil {
    /**
     * Share Text
     */
    public static final String TEXT = "text/plain";

    /**
     * Share Image
     */
    public static final String IMAGE = "image/jpeg";

    /**
     * Share Audio
     */
    public static final String AUDIO = "audio/*";

    /**
     * Share Video
     */
    public static final String VIDEO = "video/*";

    /**
     * Share File
     */
    public static final String File = "*/*";

//    public static void shareFiles(Activity activity, List<MediaUtil.MediaBean> mediaBeans){
//        ArrayList<Uri> files = new ArrayList<Uri>();
//        for(int i=0;i<mediaBeans.size();i++)
//        {
//            MediaUtil.MediaBean bean=mediaBeans.get(i);
//            files.add(MediaUtil.getUri(bean.id,bean.type));
//        }
//
//        //分享文件
//        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
//        //发送多个文件
//        intent.setType("*/*");
//        //多个文件格式
//        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,files);
//        //Intent.EXTRA_STREAM同于传输文件流
//        activity.startActivity(intent);
//    }
//
//    public static void shareFile(Activity activity, MediaUtil.MediaBean mediaBeans){
//
//        //分享文件
//        Intent intent = new Intent(Intent.ACTION_SEND);
//        Uri uri = MediaUtil.getUri(mediaBeans.id,mediaBeans.type); //path:文件地址
//        intent.putExtra(Intent.EXTRA_STREAM, uri);
//        if(mediaBeans.path.toLowerCase().endsWith("mp4"))
//        {
//            intent.setType(VIDEO);
//
////            intent.setType("*/*");
//        }
//        else {
//            intent.setType(IMAGE);
//        }
//
//        //Intent.EXTRA_STREAM同于传输文件流
//        activity.startActivity(intent);
//    }

    public static void shareLogFile(Activity activity,String fileName){

        File file = new File(fileName);
        if (null != file && file.exists()) {
            Intent share = new Intent(Intent.ACTION_SEND);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                Uri contentUri = FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".fileprovider",file);
                share.putExtra(Intent.EXTRA_STREAM, contentUri);
                share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            } else {
                share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
            }
            share.setType(File);//此处可发送多种文件
            share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            activity.startActivity(Intent.createChooser(share, "分享文件"));
        } else {

        }

    }

}
